use std::collections::HashMap;

use linfa::linalg::Inverse;
use ndarray::{prelude::*, ArcArray1};
use plotters::prelude::*;
use tensorboard_rs::summary_writer::SummaryWriter;
fn main() {
    let mut writer = SummaryWriter::new(&("./logdir".to_string()));

    for n_iter in 0..100 {
        let mut map = HashMap::new();
        map.insert("x1".to_string(), (n_iter as f32));
        map.insert("x^2".to_string(), (n_iter as f32) * (n_iter as f32));
        writer.add_scalars("data/scalar_group", &map, n_iter);
    }
    writer.flush();
    return;

    let data = array![[1.0, 2.0], [3.0, 4.0]];

    println!("{}", data);
    println!("{}", &data * 2.0);
    println!("{}", data.t());
    println!("{}", data.inv().unwrap());
    println!("{}", data.dot(&data.inv().unwrap()));
    let vector = array![1.0, 2.0];
    println!("{}", data.dot(&vector.to_shared().reshape((2, 1))));

    let re = vector.to_shared().reshape((2, 1));
    println!("{}", &data * &re);

    let data2 = array![[1.0, 2.0], [3.0, 4.0]];
    // 需要把这个矩阵变成1 4  copy
    let data3 = data2.to_shared().reshape(4);
    let data4 = data2.into_shape(4);

    hello();
}

// 在写C， 先设计内存管理框架, 或者自己实现内存引用计数Arc，或者自己实现Gc
fn hello() {
    let name: String = String::from("世界");
    let name: (usize, usize) =
        unsafe { std::mem::transmute::<&str, (usize, usize)>(&name as &str) };
    println!("0x{:X}, {}", name.0, name.1);

    let c = vec![1, 2, 3];
    let d: (usize, usize, usize) =
        unsafe { std::mem::transmute::<Vec<i32>, (usize, usize, usize)>(c) };
    println!("{:?}", d);
}
